package com.zhida.smartcontrol.pagectrl.devicedetail.newdata;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.jay.tools.web.event.Event;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.mvp.MVPBaseFragment;

import java.util.List;

import butterknife.BindViews;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 13:09
 * description: 最新数据
 */

public class NewDataFragment extends MVPBaseFragment<NewDataContract.View, NewDataPresenter> implements NewDataContract.View {
    @BindViews({R.id.tv_0, R.id.tv_1, R.id.tv_2, R.id.tv_3, R.id.tv_4, R.id.tv_5, R.id.tv_6,
            R.id.tv_7, R.id.tv_8, R.id.tv_9, R.id.tv_10, R.id.tv_11, R.id.tv_12})
    List<TextView> mTvLeft;
    @BindViews({R.id.tv_00, R.id.tv_01, R.id.tv_02, R.id.tv_03, R.id.tv_04, R.id.tv_05, R.id.tv_06,
            R.id.tv_07, R.id.tv_08, R.id.tv_09, R.id.tv_010, R.id.tv_011, R.id.tv_012})
    List<TextView> mTvRight;

    private String mCode;
    private String mSwitchType;

    public static NewDataFragment newInstance(String code, String switchType) {
        Bundle args = new Bundle();
        args.putString("code", code); //deviceId设备 code, 如果是 ZigBee 单灯，需要传递的是其所属集控的 code
        args.putString("switchType", switchType);
        NewDataFragment fragment = new NewDataFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        return R.layout.fragment_new_data;
    }

    @Override
    protected void initLazy(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        mCode = bundle.getString("code");
        mSwitchType = bundle.getString("switchType");

        mPresenter.requestData(mCode, mSwitchType);
    }

    public void requestData() {
        mPresenter.requestData(mCode, mSwitchType);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void showData(NewDataBean bean) {
        EnvironmentBean environment = bean.getEnvironment();

        mTvLeft.get(0).setText("温度：" + environment.getTemp());
        mTvLeft.get(1).setText("烟雾报警：" + getStr(environment.getSmokeFlag()));
        mTvLeft.get(2).setText("高压报警：" + getStr(environment.getVoh()));
        mTvLeft.get(3).setText("低压报警：" + getStr(environment.getVol()));
        mTvLeft.get(4).setText("电流高报警：" + getStr(environment.getCuh()));
        mTvLeft.get(5).setText("电流低报警：" + getStr(environment.getCul()));
        mTvLeft.get(6).setText("三相电缺相报警：" + getStr(environment.getLoss()));
        mTvLeft.get(7).setText("第一路输入信号：" + "否");
        mTvLeft.get(8).setText("第二路输入信号：" + "否");
        mTvLeft.get(9).setText("第三路输入信号：" + "否");
        mTvLeft.get(10).setText("第四路输入信号：" + "否");
        mTvLeft.get(11).setText("第五路输入信号：" + "否");
        mTvLeft.get(12).setText("第六路输入信号：" + "否");

        mTvRight.get(0).setText("湿度：" + environment.getHumi());
        mTvRight.get(1).setText("A相电压：" + environment.getVol1());
        mTvRight.get(2).setText("B相电压：" + environment.getVol2());
        mTvRight.get(3).setText("C相电压：" + environment.getVol3());
        mTvRight.get(4).setText("A相电流：" + environment.getCur1());
        mTvRight.get(5).setText("B相电流：" + environment.getCur2());
        mTvRight.get(6).setText("C相电流：" + environment.getCur3());
        mTvRight.get(7).setText("A相功率：" + environment.getPower1());
        mTvRight.get(8).setText("B相功率：" + environment.getPower2());
        mTvRight.get(9).setText("C相功率：" + environment.getPower3());
        mTvRight.get(10).setText("A相频率：" + environment.getPf1());
        mTvRight.get(11).setText("B相频率：" + environment.getPf2());
        mTvRight.get(12).setText("C相频率：" + environment.getPf3());
    }

    private String getStr(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        if (str.equals("0")) {
            return "否";
        } else if (str.equals("1")) {
            return "是";
        }
        return "";
    }

}
